﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="MattersResponse", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(MattersResponse))]
    public class MattersResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMattersResponse clazz;
        
        public MattersResponseSerializer(IMattersResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("OrderNumber");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.OrderNumber))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("JudicialMatterNumber");
            if (clazz.JudicialMatterNumber!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.JudicialMatterNumber))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : JudicialMatterNumber");
            }
            Writer.WriteEndElement();
            if (clazz.ErrorDescription!=null) {
                Writer.WriteStartElement("ErrorDescription");
                global::Xtee.Core.SerializationMetadata metaErrorDescription = this.GetMetaData(clazz.ErrorDescription);
                Writer.WriteTypeAttribute(metaErrorDescription.TypeQualifiedName.Namespace, metaErrorDescription.TypeQualifiedName.Name);
                metaErrorDescription.NewSerializer(clazz.ErrorDescription).WriteXml(Writer);
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="OrderNumber") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MattersResponse>OrderNumber");
                }
                clazz.OrderNumber = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("OrderNumber")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>MattersResponse>OrderNumber", Reader.LocalName);
            }
            if (Reader.LocalName=="JudicialMatterNumber") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MattersResponse>JudicialMatterNumber");
                }
                clazz.JudicialMatterNumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("JudicialMatterNumber")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>MattersResponse>JudicialMatterNumber", Reader.LocalName);
            }
            if (Reader.LocalName=="ErrorDescription") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MattersResponse>ErrorDescription");
                }
                global::Xtee.Core.SerializationMetadata metaErrorDescription = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IErrorDescriptionData>(Reader, "ErrorDescriptionData", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.ErrorDescription = metaErrorDescription.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IErrorDescriptionData>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ErrorDescription");
                    metaErrorDescription.NewSerializer(clazz.ErrorDescription).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
